package yui.comn.mybatisx.extension.injector;

import static java.util.stream.Collectors.toList;

import java.util.List;
import java.util.stream.Stream;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.AbstractSqlInjector;
import com.baomidou.mybatisplus.core.injector.methods.Delete;
import com.baomidou.mybatisplus.core.injector.methods.DeleteBatchByIds;
import com.baomidou.mybatisplus.core.injector.methods.DeleteById;
import com.baomidou.mybatisplus.core.injector.methods.DeleteByMap;
import com.baomidou.mybatisplus.core.injector.methods.Insert;
import com.baomidou.mybatisplus.core.injector.methods.Update;
import com.baomidou.mybatisplus.core.injector.methods.UpdateById;
import com.baomidou.mybatisplus.core.metadata.TableInfo;

import yui.comn.mybatisx.extension.methods.*;


/**
 * <p>
 * SQL 逻辑删除注入器
 * </p>
 *
 * @author yuyi (1060771195@qq.com)
 */
public class SoftSqlInjector extends AbstractSqlInjector {

	@Override
	public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
		Stream.Builder<AbstractMethod> builder = Stream.<AbstractMethod>builder()
				.add(new Insert())
	            .add(new SoftInsertBatch())
	            .add(new SoftDefunct())
	            .add(new Delete())
	            .add(new DeleteByMap())
	            .add(new DeleteById())
	            .add(new DeleteBatchByIds())
	            .add(new Update())
	            .add(new UpdateById())
	            .add(new SoftUpdateAllById())
	            .add(new SoftUpdateBatchById())
	            .add(new SoftUpdateBatch())
	            .add(new SoftUpdateAllBatchById())
	            .add(new SoftCount())
	            .add(new SoftGet())
	            .add(new SoftGetById())
	            .add(new SoftGetByMap())
	            .add(new SoftList())
	            .add(new SoftListByMap())
	            .add(new SoftListBatchIds())
	            .add(new SoftListObjs())
	            .add(new SoftListMaps())
	            .add(new SoftListMapsByMap())
	            .add(new SoftPage())
	            .add(new SoftPageMaps());
	        return builder.build().collect(toList());
	}
	
//	@Override
//    public void inspectInject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass) {
//        Class<?> modelClass = ReflectionKit.getSuperClassGenericType(mapperClass, BaseDao.class, 0);
//        if (modelClass != null) {
//            String className = mapperClass.toString();
//            Set<String> mapperRegistryCache = GlobalConfigUtils.getMapperRegistryCache(builderAssistant.getConfiguration());
//            if (!mapperRegistryCache.contains(className)) {
//                TableInfo tableInfo = TableInfoHelper.initTableInfo(builderAssistant, modelClass);
//                List<AbstractMethod> methodList = this.getMethodList(mapperClass, tableInfo);
//                if (CollectionUtils.isNotEmpty(methodList)) {
//                    // 循环注入自定义方法
//                    methodList.forEach(m -> m.inject(builderAssistant, mapperClass, modelClass, tableInfo));
//                } else {
//                    logger.debug(mapperClass.toString() + ", No effective injection method was found.");
//                }
//                mapperRegistryCache.add(className);
//            }
//        }
//    }

}
